package com.weiqiao.mall.repository.impl;

import com.mongodb.client.MongoCollection;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IShopkeeperRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 订单后台配置 持久化层 实现层 继承IShelfDao
 *
 * @author tiyer
 */
@Repository("ShopkeeperRepositoryImpl")
public class ShopkeeperRepositoryImpl extends BaseMongoDaoImpl implements IShopkeeperRepository {

    private String collectionName = "shopkeeper";

    @Override
    public String getOne(Bson filter) {

        String result = this.findOne(collectionName, filter);
        return result;
    }

    @Override
    public List<String> getShops(Bson filter) {
        return this.findFilter(collectionName, filter);
    }

    @Override
    public boolean updateShop(Bson filter, String json) {
        Document doc = Document.parse(json);
        return this.updateOne(collectionName, filter, doc, true);
    }

    @Override
    public List<String> getList(Bson filter) {

        List<String> list = this.findFilter(collectionName, filter);
        return list;
    }

    @Override
    public boolean updateOne(Bson filter, Document doc, boolean bool) {

        boolean result = this.updateBson(collectionName, filter, doc, bool);
        return result;
    }

    @Override
    public boolean updateShop(Bson filter, Document doc) {

        return this.updateOne(collectionName, filter, doc, true);
    }

    @Override
    public boolean updateShopByBson(Bson filter, Bson bson) {
        return this.updateBson(collectionName, filter, bson, false);
    }

    ;

    @Override
    public List<String> getShopsByFilterSortSkipLimt(int company_id, Bson bson, Bson sort, int skip, int pageSize) {

        return this.findFilterSortSkipLimit(collectionName, bson, sort, skip, pageSize);
    }

    @Override
    public int countShop(Bson bson) {
        MongoCollection<Document> dbCollection = getCollection(collectionName);
        return (int) dbCollection.count(bson);
    }

    @Override
    public List<String> queryChildEntityList(List<Document> doclist) {

        List<String> list = this.findAggregate(collectionName, doclist);
        return list;
    }

    public static void main(String[] args) {
        ShopkeeperRepositoryImpl impl = new ShopkeeperRepositoryImpl();
    }

}
